import socket
import os
import base64
os.chdir(r"D:\程序设计\pycharm\text")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1', 8001))
s.listen()
conn, address = s.accept()
name = conn.recv(1024)
print("来自", address, "的文件：", name.decode())
data = conn.recv(1024)
f = open("receive.txt", "w")
data1 = base64.b32decode(data)
f.write(data1.decode())
f.close()
print("来自", address, "加密的信息：", data.decode(), "解密后已保存为receive.txt")
conn.sendall("服务器已经收到了数据内容,准备传输文件，注意接收！".encode())
data1 = conn.recv(1024)
conn.sendall("reply.txt".encode())
f = open("receive.txt", "r")
data1 = f.read()
conn.sendall(data1.encode())
f.close()
data1 = conn.recv(1024)
print("来自", address, "的信息", data1.decode())
s.close()
